package com.group5.onlinegame.handler;

import com.group5.onlinegame.entity.Demo;
import com.group5.onlinegame.entity.Recharge;
import com.group5.onlinegame.service.ICommonService;
import com.group5.onlinegame.service.IRechargeRecordingService;
import com.group5.onlinegame.service.IRechargeService;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


import javax.annotation.Resource;
import java.io.PrintWriter;
import java.util.*;


@Controller
@RequestMapping("/")
public class tancHandler {

    @Resource
    private IRechargeService iRechargeService;

    @Resource
    private IRechargeRecordingService iRechargeRecordingService;


    @Resource
    private ICommonService iCommonService;



    /*先进页面在传值*/

    @RequestMapping("getstatistics")
    public void getstatistics(PrintWriter out) {

        List<String> categories =new  ArrayList<>();
        List<Integer> data =new  ArrayList<>();
        List<Recharge> recharges=iRechargeService.getRechargeList();
        for (Recharge r:recharges){
                categories.add (r.getName());
                data.add(iRechargeRecordingService.getmap(r.getId()));
        }

        /*调用公共getget方法*/
        String str=iCommonService.getget(categories,data);
        out.write(str);
    }


    /*先获值在传页面*/
    @RequestMapping("getstatistics2")
    public ModelAndView getstatistic() {
        ModelAndView mv=new ModelAndView("statistics2");
        List<String> categories =new  ArrayList<>();
        List<Integer> data =new  ArrayList<>();
        List<Recharge> recharges=iRechargeService.getRechargeList();
        for (Recharge r:recharges){
            categories.add (r.getName());
            data.add(iRechargeRecordingService.getmap(r.getId()));
        }
        Demo demo=iCommonService.getget2(categories,data);
        mv.addObject("data",demo);
        return mv;
    }




}
